package com.baidu.mapapi.demo;

import android.app.Application;
import android.widget.Toast;

import com.baidu.mapapi.BMapManager;
import com.baidu.mapapi.MKEvent;
import com.baidu.mapapi.MKGeneralListener;

/**
 * 
 * @author lilin
 * @date 2012-11-8 上午9:32:07
 * @annotation 百度地图全局参数
 */
public class FrameParam extends Application {

	public double my_x = 31.902278900146484;
	public double my_y = 120.54867553710938;

	public static FrameParam BMParam;

	public BMapManager mBMapManager = null;// 百度MapAPI的管理类

	public String mapKey = "D0D460F33EBFD242CCB9131EC7E1B382CBAC6B7F";// 授权Key
	public boolean isRightKey = true; // 授权Key正确，验证通过
	
	public  String tag = "andli";

	@Override
	public void onCreate() {
		BMParam = this;
		mBMapManager = new BMapManager(this);
		boolean isSuccess = mBMapManager.init(this.mapKey,
				new MyGeneralListener());

		if (isSuccess) {
			mBMapManager.getLocationManager().setNotifyInternal(10, 5);// 初始化地图sdk成功，设置定位监听时间
		} else {
			// 地图sdk初始化失败，不能使用sdk
		}

		super.onCreate();
	}

	@Override
	// 建议在您app的退出之前调用mapadpi的destroy()函数，避免重复初始化带来的时间消耗
	public void onTerminate() {
		// TODO Auto-generated method stub
		if (mBMapManager != null) {
			mBMapManager.destroy();
			mBMapManager = null;
		}
		super.onTerminate();
	}

	// 常用事件监听，用来处理通常的网络错误，授权验证错误等
	public static class MyGeneralListener implements MKGeneralListener {
		@Override
		public void onGetNetworkState(int iError) {
			Toast.makeText(FrameParam.BMParam.getApplicationContext(),
					"您的网络出错啦！", Toast.LENGTH_LONG).show();
		}

		@Override
		public void onGetPermissionState(int iError) {
			if (iError == MKEvent.ERROR_PERMISSION_DENIED) {
				// 授权Key错误：
				Toast.makeText(FrameParam.BMParam.getApplicationContext(),
						"请在BMapApiDemoApp.java文件输入正确的授权Key！", Toast.LENGTH_LONG)
						.show();
				FrameParam.BMParam.isRightKey = false;
			}
		}
	}

}
